{% extends "main_face_base.html" %}
{% load custom_filters %}

{% block styles %}
	<link rel="stylesheet" href="static/face.css" type="text/css"/>
	<link rel="stylesheet" href="static/table.css" type="text/css"/>
	<link rel="stylesheet" href="static/form_error.css" type="text/css"/>
{% endblock %}

{% block scripts %}
	<script type="text/javascript">
		function process_comment(f, action) {
			for (var i = 0; i < f.elements.length; i++)
			{
				var element = f.elements[i];
				if (element.name == 'action')
				{
					element.value = action;
					break;
				}
			}
			f.submit();
		}
		
		function donate(f, summ, cash) {
			if (cash >= summ)
			{
				alert('Вы перечислили владельцу произведения ' + summ + ' талантов за его труд. Благодарим за щедрость!');
			}
			f.submit();
		}
	</script>
{% endblock %}

{% block content_block_left %}
	<div>
		{% if locked or not is_authorized or not is_published or contest %}
			&nbsp;
		{% else %}
			{% if like %}
				<p id="vote_text">Ваш голос засчитан<br/>(вам нравится это произведение)</p>
			{% else %}
				{% if dislike %}
					<p id="vote_text">Ваш голос засчитан<br/>(вам не нравится это произведение)</p>
				{% endif %}
			{% endif %}
			<ul>
				{% ifequal view_price None %}
					{% if not is_master and not like and not dislike %}
						<li>
							<form action="table?view={{work_id}}" method="post" enctype="multipart/form-data">
								<input style="color:#00FF00;" type="submit" value="Нравится" id="id_like" name="like"/>
							</form>
						</li>
						<li>
							<form action="table?view={{work_id}}" method="post" enctype="multipart/form-data">
								<input style="color:#FF5656;" type="submit" value="Не нравится" id="id_dislike" name="dislike"/>
							</form>
						</li>
					{% endif %}
					<li>
						<form action="table?view={{work_id}}" method="post" enctype="multipart/form-data">
							<input type="submit" {% if is_recommend %} value="Не рекомендовать" id="id_unrecommend" name="unrecommend" {% else %} value="Рекомендовать" id="id_recommend" name="recommend" {% endif %}/>
						</form>
					</li>
					<li>
						<form action="table?view={{work_id}}" method="post" enctype="multipart/form-data">
							<input type="submit" {% if is_favorite %} value="Из избранного" id="id_unfavorite" name="unfavorite" {% else %} value="В избранное" id="id_favorite" name="favorite" {% endif %}/>
						</form>
					</li>
				{% else %}
					<li>
						<p id="view_pay">Доступ: <span class="view_price">{{view_price}}</span> талантов</p>
						<form action="table?view={{work_id}}" method="post" enctype="multipart/form-data">
							<input type="submit" value="Оплатить доступ" id="id_pay" name="pay"/>
						</form>
					</li>
				{% endifequal %}
			</ul>
			{% if is_master and is_published %}
				<ul id="master_list">
					<li>
						<p><a href="work?id={{work_id}};action=publish">Изменить публикацию</a></p>
					</li>
					<li>
						<p><a href="work?id={{work_id}};action=edition">Новая редакция</a></p>
					</li>
				</ul>
			{% endif %}
			{% if pages and not is_master %}
				<ul id="donate_list">
					<li>
						<form id="donate1_form" action="table?view={{work_id}}" method="post" enctype="multipart/form-data">
							<input type="hidden" id="id_donate1" name="donate1" value="1"/>
							<p><a href=# style="color:#CC857C;" onclick="donate(document.getElementById('donate1_form'), 1, {{cash}})">"Благодарю!" (<span class="view_price">1</span> <span class="price_sign">талант</span>)</a></p>
						</form>
					</li>
					<li>
						<form id="donate5_form" action="table?view={{work_id}}" method="post" enctype="multipart/form-data">
							<input type="hidden" id="id_donate5" name="donate5" value="5"/>
							<p><a href=# style="color:#DBDBDB;" onclick="donate(document.getElementById('donate5_form'), 5, {{cash}})">"Благодарю!" (<span class="view_price">5</span> <span class="price_sign">талантов</span>)</a></p>
						</form>
					</li>
					<li>
						<form id="donate10_form" action="table?view={{work_id}}" method="post" enctype="multipart/form-data">
							<input type="hidden" id="id_donate10" name="donate10" value="10"/>
							<p><a href=# style="color:#FF954F;" onclick="donate(document.getElementById('donate10_form'), 10, {{cash}})">"Благодарю!" (<span class="view_price">10</span> <span class="price_sign">талантов</span>)</a></p>
						</form>
					</li>
				</ul>
			{% endif %}
			{% if visit and unique or summ %}
				<div id="visit_block">
					<ul>
						<li>
							<label>Посещений:</label>
							<p>{{visit}}</p>
						</li>
						<li>
							<label>Уникальных посетителей:</label>
							<p>{{unique}}</p>
						</li>
						{% if is_master %}
						<li>
							<label style="color: yellow;">Собрано талантов:</label>
							<p style="color: yellow;">{{summ}}</p>
						</li>
						{% endif %}
					</ul>
				</div>
			{% endif %}
		{% endif %}
	</div>
{% endblock %}

{% block document_title %}HOME - {{work_title}}{% endblock %}

{% block title_center %}<p>{{work_title}}</p>{% endblock %}

{% block title_right %}<!--div>&nbsp;</div-->{% endblock %}

{% block content_block_center %}
	<div id="view_container">
		{% if fosterling %}
			<p id="fosterling_string">Рецензия на произведение <a href="table?view={{fosterling.id}}">"{{fosterling.title}}"</a></p>
		{% endif %}
		{% if annotation %}
			<div id="annotation_block">
				{{annotation}}
			</div>
		{% endif %}
		{% if pages %}
			<div id="text_block">
				<h1>{{work_title}}</h1>
				{% for page in pages %}
					{% if page.title %}
						<h2>{{page.title}}</h2>
					{% else %}
						{% if pages|length > 1 %}
							<p class="separator">* * *</p>
						{% endif %}
					{% endif %}
					{{page.text|page_to_html}}
				{% endfor %}
			</div>
		{% endif %}
		{% if date %}
			<p id="signature"><a href="cabinet?view={{author_id}}">{{signature}}</a> ({{date|date:"d.m.Y"}})</p>
		{% endif %}
		{% if contest %}
			<p id="contest_message">Это произведение участвует в <a href="board?view={{contest.id}}">Конкурсе на тему <b>"{{contest.title}}"</b></a>.</p>
		{% else %}
			{% if message %}
				<div id="view_message_block">
					{{message|safe}}
				</div>
			{% endif %}
			{% if reviews or can_review %}
				<div id="review_block">
					{% if reviews %}
						<p id="reviews_title"><b>"{{work_title}}"</b> - рецензии:</p>
						<ul>
							{% for review in reviews %}
								<li>
									<p><a href="table?view={{review.id}}">{{review.title}}</a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="review_author">(<a href="cabinet?view={{review.author.id}}">{{review.signature}}</a>)</span></p>
								</li>
							{% endfor %}
						</ul>
						{% if can_review %}
							<div id="spacer">&nbsp;</div>
						{% endif %}
					{% endif %}
					{% if can_review %}
						<form action="table?view={{work_id}}" method="post" enctype="multipart/form-data" id="buy_form">
							<p>Вы можете написать свою рецензию на это произведение.</p>
							<input type="submit" value="Написать рецензию" id="id_review" name="review"/>
						</form>
					{% endif %}
				</div>
			{% endif %}
		{% endif %}
		{% if comments %}
		<div id="comments_container">
			{% if im_banned %}
			<p id="im_banned_msg">Вам запрещено оставлять комментарии к этому произведению</p>
			{% endif %}
			<ul>
				{% for comment in comments %}
					<li style="margin-left: {{comment.level|mul:"20"}}px">
						<a name="a{{comment.comment.id}}"></a>
						{% if can_comment and not im_banned %}
						{% ifnotequal comment.comment.id target_comment %}
							<form class="comment_title_form" id="{{comment.comment.id}}_form" action="comment" method="post" enctype="multipart/form-data">
								<input type="hidden" name="action" value="answer"/>
								<input type="hidden" name="work" value="{{work_id}}"/>
								<input type="hidden" name="comment" value="{{comment.comment.id}}"/>
								<p>
									{% if comment.can_ban %}
										{% if comment.banned %}
										{% else %}
										{% if comment.work_banned %}
											<a href="#a{{comment.comment.id}}" onclick="process_comment(document.getElementById('{{comment.comment.id}}_form'), 'unban')">Разрешить</a>&nbsp;&nbsp;
										{% else %}
											<a href="#a{{comment.comment.id}}" onclick="process_comment(document.getElementById('{{comment.comment.id}}_form'), 'ban')">Запретить</a>&nbsp;&nbsp;
										{% endif %}
										{% endif %}
									{% endif %}
									{% if comment.can_ban or comment.can_del %}
										<a href="#a{{comment.comment.id}}" onclick="process_comment(document.getElementById('{{comment.comment.id}}_form'), 'del')">Удалить</a>&nbsp;&nbsp;
									{% endif %}
									<a href="#a{{comment.comment.id}}" onclick="process_comment(document.getElementById('{{comment.comment.id}}_form'), 'answer')">{% if comment.level == 0 %}Оставить комментарий{% else %}Ответить{% endif %}</a>
								</p>
							</form>
						{% else %}
						{% if comment.level > 0 %}<div class="comment_separator">&nbsp;</div>{% endif %}
						{% endifnotequal %}
						{% else %}
						{% if comment.level > 0 %}<div class="comment_separator">&nbsp;</div>{% endif %}
						{% endif %}
						{% if comment.level > 0 and comment.comment.text %}
							<div>
								{% if comment.banned or comment.work_banned %}
									<p class="ban">Владелец произведения запретил комментарии от этого пользователя.</p>
								{% else %}
								{% if comment.ignored %}
									<p class="ignor">Вы игнорируете автора этого комментария.</p>
								{% else %}								
									<h1>{{comment.comment.title}}</h1>
									<p>{{comment.comment.text|multiline_to_html}}</p>
								{% endif %}
								{% endif %}
								<p class="comment_sign">({{comment.comment.date|date:"H:i d.m.Y"}}) <a href="cabinet?view={{comment.author_id}}">{{comment.author}}</a></p>
							</div>
						{% endif %}
						{% ifequal comment.comment.id target_comment %}
							<form name="comment_submit_form" id="{{comment.comment.id}}_answ_form" action="comment" method="post" enctype="multipart/form-data">
								<input type="hidden" name="work" value="{{work_id}}"/>
								<input type="hidden" name="root" value="{{comment.comment.id}}"/>
								<input id="id_{{comment.comment.id}}_title" type="text" name="title" maxlength="127" value="Re. {{comment.comment.title}}"/>
								<textarea id="id_{{comment.comment.id}}_answer" name="answer" rows="5"></textarea>
								<div>
									<div>
										<input type="submit" value="Отправить"/>
									</div>
								</div>
							</form>
						{% endifequal %}
					</li>
				{% endfor %}				
			</ul>
		</div>
		{% endif %}
		{% if price and not contest %}
			<form action="table?view={{work_id}}" method="post" enctype="multipart/form-data" id="buy_form">
				<p>Вы можете <a href="about">купить права</a> на это произведение за <span class="buy_price">{{price}}</span> талантов.</p>
				<input type="submit" value="Купить" id="id_buy" name="buy"/>
			</form>
		{% endif %}
	</div>
{% endblock %}

{% block content_right %}
	<!--div id="body_right">
	</div-->
{% endblock %}
